/**
 * @file DataTransfer
 * @date 2025/11/19 14:32:32
 * @author lyqjob@yeah.net
 */

import {  memo  } from 'react';
import zhCN from 'antd/locale/zh_CN.js';

import { Table, Transfer } from 'antd';
// Customize Table Transfer
const TableTransfer = props => {
  const { leftColumns, rightColumns, ...restProps } = props;
  return (
    <Transfer style={{ width: '100%' }} {...restProps}>
      {({
        direction,
        filteredItems,
        onItemSelect,
        onItemSelectAll,
        selectedKeys: listSelectedKeys,
        disabled: listDisabled,
      }) => {
        const columns = direction === 'left' ? leftColumns : rightColumns;
        const rowSelection = {
          getCheckboxProps: record => ({
                disabled: record.is_protected === 1, // Column configuration not to be checked
            }),
          onChange(selectedRowKeys) {
            onItemSelectAll(selectedRowKeys, 'replace');
          },
          selectedRowKeys: listSelectedKeys,
          selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT, Table.SELECTION_NONE],
        };
        return (
          <Table
            locale={zhCN}
            rowKey="id"
            rowSelection={rowSelection}
            columns={columns}
            dataSource={filteredItems}
            size="small"
            style={{ pointerEvents: listDisabled ? 'none' : undefined }}
            onRow={(record) => ({
              onClick: () => {
                if (record.is_protected === 1) {return;}
                onItemSelect(record.key, !listSelectedKeys.includes(record.key));
              }
            })}
          />
        );
      }}
    </Transfer>
  );
};


export default memo(TableTransfer);